package com.sam.designpattern.builder;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

/**
 * @Author: Sam
 * @Date: 2022-07-25 10:17
 * @Description: 生成器客户端
 */
public class Client {
    @Test
    public void test1() {
        ExportHeaderModel ehm = new ExportHeaderModel();
        ehm.setDeptId("一分公司");
        ehm.setExportDate("2022-07-25");
        HashMap<String, Collection<ExportDataModel>> mapData = new HashMap<>();
        Collection<ExportDataModel> col = new ArrayList<>();
        ExportDataModel edm1 = new ExportDataModel();
        edm1.setProductId("产品001号");
        edm1.setPrice(100d);
        edm1.setAmount(80d);
        ExportDataModel edm2 = new ExportDataModel();
        edm2.setProductId("产品002号");
        edm2.setPrice(99d);
        edm2.setAmount(55d);
        col.add(edm1);
        col.add(edm2);
        mapData.put("销售记录表", col);

        ExportFooterModel efm = new ExportFooterModel();
        efm.setExportUser("张三");

        //测试输出到文本文件
        TxtBuilder txtBuilder = new TxtBuilder();
        //创建指导者对象
        Director director = new Director(txtBuilder);
        director.construct(ehm, mapData, efm);
        //输出控制台
        System.out.println("输出到文本文件的内容：\n" + txtBuilder.getResult());

        XmlBuilder xmlBuilder = new XmlBuilder();
        Director director2 = new Director(xmlBuilder);
        director2.construct(ehm, mapData, efm);
        System.out.println("输出到xml文件的内容：\n" + xmlBuilder.getResult());
    }

    @Test
    public void test2() {
        AuthConfigBuilder authConfigBuilder = new AuthConfigBuilder("ASDJiuNV", "FOYWInlxUI", 1200 * 60);
        AuthConfig authConfig = authConfigBuilder.build();
        System.out.println("authConfig = " + authConfig);
    }
}
